#if TOOLS
using Godot;
using Godot.Collections;

namespace Janphe.addons.Avatar
{
    [Tool]
    public class PluginControl : Control
    {
        public Main main { private get; set; }

        public void Start()
        {
            Name = "Avatar";

            var vbox = GetNode("CenterContainer/VBoxContainer");

            var args = new Array();

            for (var i = 0; i < (int)Method.count; ++i)
            {
                var btn = new Button();
                btn.Name = $"{i:d2}_{(Method)i}";
                btn.Text = Tr($"{(Method)i}");
                btn.Connect("button_down", this, nameof(on_btn_down), new Array() { i, btn });

                vbox.AddChild(btn);
            }
        }

        enum Method
        {
            Skeleton2Nodes,//骨头解成成节点
            Nodes2Skeleton,//节点打包成骨头
            Nodes2Config,//保存节点路径字符串到一个文件

            ResortSkeleton,//骨骼排序，且修改骨头名称跟Pose-T.tscn一致
            Dis_Rest_OrNot,//切换骨骼静态激活状态
            MeshT_Skeleton,//骨骼T型姿态Transform
            Rest_2_Pose,//骨骼静态Transform转为姿势Transform
            Pose_2_Rest,//骨骼姿势Transform转为静态Transform

            ReportAnimation1,
            ReportAnimationN,//导入当前目录所有动画到播放器，且修改通道名称跟Pose-T.tscn一致
            count
        }
        private void on_btn_down(int i, Button btn)
        {
            var editor = main.GetEditorInterface();

            switch ((Method)i)
            {
                case Method.Skeleton2Nodes:
                    Plugin_RestructSkeleton.Skeleton2Nodes(editor);
                    break;
                case Method.Nodes2Skeleton:
                    Plugin_RestructSkeleton.Nodes2Skeleton(editor);
                    break;
                case Method.Nodes2Config:
                    Plugin_RestructSkeleton.Nodes2Config(editor);
                    break;
                case Method.ResortSkeleton:
                    Plugin_RestructSkeleton.ResortSkeleton2(editor);
                    break;
                case Method.Dis_Rest_OrNot:
                    Plugin_RestructSkeleton.Dis_Rest_OrNot(editor);
                    break;
                case Method.Rest_2_Pose:
                    Plugin_RestructSkeleton.Rest_2_Pose(editor);
                    break;
                case Method.Pose_2_Rest:
                    Plugin_RestructSkeleton.Pose_2_Rest(editor);
                    break;

                case Method.ReportAnimation1:
                    Plugin_CollectAnimation.ReportAnimation1(editor);
                    break;
                case Method.ReportAnimationN:
                    Plugin_CollectAnimation.ReportAnimationN(editor);
                    break;
            }
        }

        public override void _Ready()
        {
            base._Ready();

        }

        public override void _Notification(int what)
        {
            //GD.Print($"_Notification {what}");
        }
    }
}
#endif

